﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TestWeb
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 登入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            var txtUserName = TextBox1.Text.Trim();
            var txtUserPwd = TextBox2.Text.Trim();

            string sql = "select * from Users where Username='" + txtUserName + "'";
            DataTable table = DbHelper.GetDataTable(sql);

  
            //是否存在
            if (table.Rows.Count == 1)
            {
                var d = (bool)table.Rows[0].ItemArray[4];
                //是否删除
                if (!(bool)table.Rows[0].ItemArray[4] )
                {
                    //是否可用
                    if ((bool)table.Rows[0].ItemArray[3])
                    {
                        //密码是否有误
                        if (table.Rows[0].ItemArray[2].ToString() == txtUserPwd)
                        {
                            Response.Redirect("Default.aspx");
                        }
                        else
                        {
                            Label4.Text = "密码错误，请重试";
                            Label4.Visible = true;
                        }
                    }
                    else
                    {
                        Label4.Text = "账号暂时不能使用";
                        Label4.Visible = true;
                    }
                }
                else
                {
                    Label4.Text = "账号已删除";
                    Label4.Visible = true;
                }
            }
            else
            {
                Label4.Text = "账号不存在";
                Label4.Visible = true;
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("Register.aspx");
        }
    }
}